### -*- coding: utf-8 -*- #############################################
# Разработано Паэглит Арвидом (http://arvid.dp.ua/)
# Все права защищены, 2007
#
# Developed by Paeglit Arvid (http://arvid.dp.ua/)
# All right reserved, 2007
#######################################################################
"""Handlers class for the Zope 3 based permissionhandler package

$Id: handler.py 34 2007-12-11 02:06:48Z Arvi3D $

"""
__author__  = "Arvid"
__license__ = "GPL"
__version__ = "$Revision: 34 $"
__date__ = "$Date: 2007-12-11 02:06:48 +0000 (Tue, 11 Dec 2007) $"

from zope.app import zapi
from zope.app.securitypolicy.interfaces import IPrincipalRoleManager, IPrincipalPermissionManager

def asignMemberRole(obj, event):
    prinrole = IPrincipalRoleManager(zapi.getSiteManager(context = obj).__parent__)
    prinrole.assignRoleToPrincipal('zope.Member', zapi.principals().prefix + str(obj.auth_id))

def removeInteractionSettings(obj, event):
    principal_id = zapi.principals().prefix + str(obj.auth_id)

    prinrole = IPrincipalRoleManager(zapi.getSiteManager(context = event.oldParent).__parent__)
    for role, settings in prinrole.getRolesForPrincipal(principal_id):
        prinrole.unsetRoleForPrincipal(role, principal_id)

    prinperm = IPrincipalPermissionManager(zapi.getSiteManager(context = event.oldParent).__parent__)
    for perm, settings in prinperm.getPermissionsForPrincipal(principal_id):
        prinperm.unsetPermissionForPrincipal(perm, principal_id)

